from pyftpdlib.authorizers import DummyAuthorizer
from pyftpdlib.handlers import FTPHandler
from pyftpdlib.servers import FTPServer
import configparser

# 创建一个配置文件解析器
config = configparser.ConfigParser()
config.read('ftp_config.ini')

# 从配置文件中读取用户名、密码、路径和端口号
username = config.get('ftp_user', 'username')
password = config.get('ftp_user', 'password')
ftp_folder = config.get('ftp_user', 'ftp_folder')
port = config.getint('ftp_user', 'port')

# 创建一个FTP服务器的虚拟用户
authorizer = DummyAuthorizer()
authorizer.add_user(username, password, ftp_folder, perm="elradfmw")

# 创建FTP处理程序
handler = FTPHandler
handler.authorizer = authorizer

# 创建FTP服务器
server = FTPServer(("0.0.0.0", port), handler)

# 启动FTP服务器
server.serve_forever()
